<?php

require_once BaseUtil::getModulePath("base") . '/forms/BaseForm.php';
require_once BaseUtil::getModulePath("base") . '/validate/Unique.php';

class EmailTemplateForm extends BaseForm {
	public function __construct($edit = false,$templateId = null){
		parent::__construct();
		if($edit){
			$this->setAction(HttpUtil::getUrl("emailtemplate","subedit"));
		}else{
			$this->setAction(HttpUtil::getUrl("emailtemplate","subadd"));
		}
		
		//id
		if($edit){
			$id = new Zend_Form_Element_Hidden('id');
			$this->addElement($id);
		}
		
		//unique validate
		$validaUnique = new MyValid_Unique();
		$validaUnique->setTableName('email_templates');
		$validaUnique->setFieldName('tag');
		if(!empty($templateId)){
			$validaUnique->setId($templateId);
		}
				
		//EmailTemplate subject
		$subject = new Zend_Form_Element_Text('subject');
		$subject->setLabel($this->translate->_('subject'));
		$subject->addFilter("StringTrim");		
		$subject->setRequired(true);
				
		//EmailTemplate sender
		$sender = new Zend_Form_Element_Text('sender');
		$sender->setLabel($this->translate->_('sender'));
		$sender->addFilter("StringTrim");		
		$sender->setRequired(true);
		
		//EmailTemplate tag
		$tag = new Zend_Form_Element_Text('tag');
		$tag->setLabel($this->translate->_('tag'));
		$tag->addFilter("StringTrim");				
		$tag->setRequired(true);
		$tag->addValidator($validaUnique);
		
		//EmailTemplate content
		$content = new Zend_Form_Element_Textarea('content');
		$content->setLabel($this->translate->_('content'));
		$content->setAttribs(array("rows" => 10,"cols" => 50));
		$content->addFilter("StringTrim");	
		
		$this->addElements(array($subject,$sender,$tag,$content));
		$this->setElementDecorators( array('ViewHelper',array(array('div' => 'HtmlTag'),array('tag' => 'div',"class" => "form_element"))));
	}
}